package com.wendy.common.core.page;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class OrderByItem implements Serializable {
    private static final long serialVersionUID = 1L;
    private String column;
    private boolean asc = true;

    public static OrderByItem asc(String column) {
        return build(column, true);
    }

    public static OrderByItem desc(String column) {
        return build(column, false);
    }

    public static List<OrderByItem> ascs(String... columns) {
        return (List) Arrays.stream(columns).map(OrderByItem::asc).collect(Collectors.toList());
    }

    public static List<OrderByItem> descs(String... columns) {
        return (List)Arrays.stream(columns).map(OrderByItem::desc).collect(Collectors.toList());
    }

    private static OrderByItem build(String column, boolean asc) {
        return new OrderByItem(column, asc);
    }

    public String getColumn() {
        return this.column;
    }

    public boolean getIsAsc() {
        return this.asc;
    }

    public void setColumn(final String column) {
        this.column = column;
    }

    public void setAsc(final boolean asc) {
        this.asc = asc;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof OrderByItem)) {
            return false;
        } else {
            OrderByItem other = (OrderByItem)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getIsAsc() != other.getIsAsc()) {
                return false;
            } else {
                Object this$column = this.getColumn();
                Object other$column = other.getColumn();
                if (this$column == null) {
                    if (other$column != null) {
                        return false;
                    }
                } else if (!this$column.equals(other$column)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof OrderByItem;
    }



    public String toString() {
        return "OrderItem(column=" + this.getColumn() + ", asc=" + this.getIsAsc() + ")";
    }

    public OrderByItem() {
    }
    public OrderByItem(String sqlOrderColumn) {
    }

    public OrderByItem(final String column, final boolean asc) {
        this.column = column;
        this.asc = asc;
    }
}
